﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using QLKTX1._0.DAO;
using QLKTX1._0.DTO;
namespace QLKTX1._0.GUI
{
    public partial class FrmQLSV : Form
    {
        public FrmQLSV()
        {
            InitializeComponent();
        }

        private void FrmQLSV_Load(object sender, EventArgs e)
        {
            //--------------LOAD DATAGRIDVIEW LOP-------------------------------------

            dtgvLop.DataSource = LopDAO.dsLop();
            //doi ten cot sang tieng viet--------------------------
            dtgvLop.Columns[0].HeaderText = "     Mã Lớp     ";
            dtgvLop.Columns[1].HeaderText = "     Tên Lớp     ";
            //Chinh do rong cua cot..............
            dtgvLop.Columns[0].Width = 165;
            dtgvLop.Columns[1].Width = 260;
            //Cam chinh sua cot, chi doc.............
            dtgvLop.Columns[0].ReadOnly = true;
            dtgvLop.Columns[1].ReadOnly = true;
            //gan du lieu gridview len textbox-------------------------------
            txtlMaLop.DataBindings.Clear();
            txtlMaLop.DataBindings.Add("Text", dtgvLop.DataSource, "maLop");
            txtlTenLop.DataBindings.Clear();
            txtlTenLop.DataBindings.Add("Text", dtgvLop.DataSource, "tenLop");
            //-------------
            this.xuLyTabLop(true, true, true, false, true , true );
            lbTSDML.Text = "Tổng số danh mục lớp là: " + LopDAO.dsLop().Count.ToString();


            //--------------LOAD DATAGRIDVIEW KHOA-------------------------------------
            dtgvKhoa.DataSource = KhoaDAO.dsKhoa();
            //doi ten cot sang tieng viet--------------------------
            dtgvKhoa.Columns[0].HeaderText = "Mã Khoa";
            dtgvKhoa.Columns[1].HeaderText = "Tên Khoa";
            //Chinh do rong cua cot..............
            dtgvKhoa.Columns[0].Width = 165;
            dtgvKhoa.Columns[1].Width = 260;
            //Cam chinh sua cot, chi doc.............
            dtgvKhoa.Columns[0].ReadOnly = true;
            dtgvKhoa.Columns[1].ReadOnly = true;
            //gan du lieu gridview len textbox-------------------------------
            txtkMaKhoa.DataBindings.Clear();
            txtkMaKhoa.DataBindings.Add("Text", dtgvKhoa.DataSource, "maKhoa");
            txtkTenKhoa.DataBindings.Clear();
            txtkTenKhoa.DataBindings.Add("Text", dtgvKhoa.DataSource, "tenKhoa");
            //------------
            this.xuLyTabKhoa(true, true, true, false, true, true );
            lbTSDMK.Text = "Tổng số danh mục Khoa là: " + KhoaDAO.dsKhoa().Count.ToString();
        


            //--------------LOAD DATAGRIDVIEW DAN TOC---------------------------
            dtgvDanToc.DataSource = DanTocDAO.dsDanToc();
            //doi ten cot sang tieng viet--------------------------
            dtgvDanToc.Columns[0].HeaderText = "Mã Dân Tộc";
            dtgvDanToc.Columns[1].HeaderText = "Tên Dân Tộc";
            //Chinh do rong cua cot..............
            dtgvDanToc.Columns[0].Width = 165;
            dtgvDanToc.Columns[1].Width = 260;
            //Cam chinh sua cot, chi doc.............
            dtgvDanToc.Columns[0].ReadOnly = true;
            dtgvDanToc.Columns[1].ReadOnly = true;
            //gan du lieu gridview len textbox----------------------------------------
            txtdtMaDanToc.DataBindings.Clear();
            txtdtMaDanToc.DataBindings.Add("Text", dtgvDanToc.DataSource, "maDanToc");
            txtdtTenDanToc.DataBindings.Clear();
            txtdtTenDanToc.DataBindings.Add("Text", dtgvDanToc.DataSource, "tenDanToc");
            //-------------------------------------------------------
            this.xuLyTabDanToc(true, true, true, false, true , true );
            lbTSDMDT.Text = "Tổng số danh mục Dân Tộc là: " + DanTocDAO .dsDanToc ().Count .ToString ();
          


            //--------------LOAD DATAGRIDVIEW TON GIAO---------------------------
            dtgvTonGiao.DataSource = TonGiaoDAO.dsTonGiao();
            //doi ten cot sang tieng viet--------------------------
            dtgvTonGiao.Columns[0].HeaderText = "Mã Tôn Giáo";
            dtgvTonGiao.Columns[1].HeaderText = "Tên Tôn Giáo";
            //Chinh do rong cua cot..............
            dtgvTonGiao.Columns[0].Width = 165;
            dtgvTonGiao.Columns[1].Width = 260;
            //Cam chinh sua cot, chi doc.............
            dtgvTonGiao.Columns[0].ReadOnly = true;
            dtgvTonGiao.Columns[1].ReadOnly = true;
            //gan du lieu gridview len textbox-------------------------------
            txttgMaTonGiao.DataBindings.Clear();
            txttgMaTonGiao.DataBindings.Add("Text", dtgvTonGiao.DataSource, "maTonGiao");
            txttgTenTonGiao.DataBindings.Clear();
            txttgTenTonGiao.DataBindings.Add("Text", dtgvTonGiao.DataSource, "tenTonGiao");
            //------------
            this.xuLyTabTonGiao(true, true, true, false, true , true );
            lbTSDMTG.Text = "Tổng số danh mục Ton Giáo là: " + TonGiaoDAO .dsTonGiao ().Count .ToString ();


            //--------------LOAD DATAGRIDVIEW Quan He--------------------------------------------//
            dtgvQuanHe.DataSource = QuanHeDAO.dsQuanHe();
            //doi ten cot sang tieng viet---------------------
            dtgvQuanHe.Columns[0].HeaderText = "Mã Tôn Giáo";
            dtgvQuanHe.Columns[1].HeaderText = "Tên Tôn Giáo";
            //Chinh do rong cua cot------------
            dtgvQuanHe.Columns[0].Width = 165;
            dtgvQuanHe.Columns[1].Width = 260;
            //Cam chinh sua cot, chi doc----------
            dtgvQuanHe.Columns[0].ReadOnly = true;
            dtgvQuanHe.Columns[1].ReadOnly = true;
            //gan du lieu gridview len textbox------------------------------------------
            txtqhMaQuanHe.DataBindings.Clear();
            txtqhMaQuanHe.DataBindings.Add("Text", dtgvQuanHe.DataSource, "maQuanHe");
            txtqhTenQuanHe.DataBindings.Clear();
            txtqhTenQuanHe.DataBindings.Add("Text", dtgvQuanHe.DataSource, "tenQuanHe");
            //------------
            this.xuLyTabQuanHe(true, true, true, false  , true , true);
            lbTSDMQH.Text = "Tổng số danh mục Quan Hệ là: " + QuanHeDAO .dsQuanHe ().Count .ToString ();

            //--------------LOAD DATAGRIDVIEW NAMHOC--------------------------------------------------//
            dtgvNamHoc.DataSource = NamHocDAO.dsNamHoc();
            //doi ten cot sang tieng viet---------------------
            dtgvNamHoc.Columns[0].HeaderText = "Mã Năm Học";
            dtgvNamHoc.Columns[1].HeaderText = "Tên Năm Học";
            //Chinh do rong cua cot-----------
            dtgvNamHoc.Columns[0].Width = 165;
            dtgvNamHoc.Columns[1].Width = 260;
            //Cam chinh sua cot, chi doc----------
            dtgvNamHoc.Columns[0].ReadOnly = true;
            dtgvNamHoc.Columns[1].ReadOnly = true;
            //gan du lieu gridview len textbox------------------------------------------
            txtnhMaNamHoc.DataBindings.Clear();
            txtnhMaNamHoc.DataBindings.Add("Text", dtgvNamHoc.DataSource, "maNamHoc");
            txtnhTenNamHoc.DataBindings.Clear();
            txtnhTenNamHoc.DataBindings.Add("Text", dtgvNamHoc.DataSource, "tenNamHoc");
            btnnhLuu.Enabled = false;

            lbTSDMNH.Text = "Tổng số danh mục Năm Học là: " + NamHocDAO.dsNamHoc().Count .ToString ();    
                     

        }

        //-------------------Ham xu ly an textbox vs Button LOP ---------------------------------------//
        private void xuLyTabLop(bool them, bool capnhat, bool xoa, bool luu, bool matang, bool tentang)
        {
            btnlThem.Enabled = them;
            btnlCapNhat.Enabled = capnhat;
            btnlXoa.Enabled = xoa;
            btnlLuu.Enabled = luu;
            txtlMaLop.Enabled = matang;
            txtlTenLop.Enabled = tentang;
        }
        //-------------------Ham xu ly an textbox vs Button KHOA ---------------------------------------//
        private void xuLyTabKhoa(bool them, bool capnhat, bool xoa, bool luu, bool matang, bool tentang)
        {
            btnkThem.Enabled = them;
            btnkCapNhat.Enabled = capnhat;
            btnkXoa.Enabled = xoa;
            btnkLuu.Enabled = luu;
            txtkMaKhoa.Enabled = matang;
            txtkTenKhoa.Enabled = tentang;
        }
        //-------------------Ham xu ly an textbox vs Button DAN TOC ---------------------------------------//
        private void xuLyTabDanToc(bool them, bool capnhat, bool xoa, bool luu, bool matang, bool tentang)
        {
            btndtThem.Enabled = them;
            btndtCapNhat.Enabled = capnhat;
            btndtXoa.Enabled = xoa;
            btndtLuu.Enabled = luu;
            txtdtMaDanToc.Enabled = matang;
            txtdtTenDanToc.Enabled = tentang;
        }
        //-------------------Ham xu ly an textbox vs Button TON GIAO ---------------------------------------//
        private void xuLyTabTonGiao(bool them, bool capnhat, bool xoa, bool luu, bool matang, bool tentang)
        {
            btntgThem.Enabled = them;
            btntgCapNhat.Enabled = capnhat;
            btntgXoa.Enabled = xoa;
            btntgLuu.Enabled = luu;
            txttgMaTonGiao.Enabled  = matang;
            txttgTenTonGiao.Enabled = tentang;
        }
        //-------------------Ham xu ly an textbox vs Button QUAN HE ---------------------------------------//
        private void xuLyTabQuanHe(bool them, bool capnhat, bool xoa, bool luu, bool matang, bool tentang)
        {
            btnqhThem.Enabled = them;
            btnqhCapNhat.Enabled = capnhat;
            btnqhXoa.Enabled = xoa;
            btnqhLuu.Enabled = luu;
            txtqhMaQuanHe.Enabled = matang;
            txtqhTenQuanHe.Enabled = tentang;
        }
        //-------------------Ham xu ly an textbox vs Button QUAN HE ---------------------------------------//
        private void xuLyTabNamHoc(bool them, bool capnhat, bool xoa, bool luu, bool matang, bool tentang)
        {
            btnnhThem.Enabled = them;
            btnnhCapNhat.Enabled = capnhat;
            btnnhXoa.Enabled = xoa;
            btnnhLuu.Enabled = luu;
            txtnhMaNamHoc.Enabled = matang;
            txtnhTenNamHoc.Enabled = tentang;
        }

        //------------------------QUAN LY DANH MUC LOP---------------------------//
        //*************THEM************************************
        private void btnlThem_Click(object sender, EventArgs e)
        {
            if (btnlThem.Text.Equals("Thêm"))
            {
                this.xuLyTabLop(true, false, false, true , false , true);
                txtlMaLop.Text = "";
                txtlTenLop.Text = "";
                btnlThem.Text = "Hủy bỏ";
            }
            else
            {
                btnlThem.Text = "Thêm";
                this.xuLyTabLop(true, true, true, false, false, false);
                this.FrmQLSV_Load(sender, e);
            } 
        }
        //*************LUU************************************
        private void btnlLuu_Click(object sender, EventArgs e)
        {
            if (btnlThem.Text.Equals("Hủy bỏ"))
            {
                if (txtlTenLop.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    
                    LopDTO l = new LopDTO();
                    l.TenLop = txtlTenLop.Text;

                    LopDAO.themLop(l);
                    
                    btnlThem.Text = "Thêm";
                    this.FrmQLSV_Load(sender, e);
                }
            }
            else
            {
                if ( txtlTenLop.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    LopDTO l = new LopDTO();
                    l.MaLop = Int32.Parse(txtlMaLop.Text);
                    l.TenLop = txtlTenLop.Text;

                    LopDAO.capNhatLop(l);
                   
                    // huy bo
                    btnlCapNhat.Text = "Cập Nhật";

                    this.FrmQLSV_Load(sender, e);
                }
            }
        }
        //*************CAP NHAT************************************
        private void btnlCapNhat_Click(object sender, EventArgs e)
        {
            if (btnlCapNhat.Text.Equals("Cập Nhật"))
            {
                this.xuLyTabLop(false, true, false, true, false, true);
                btnlCapNhat.Text = "Hủy bỏ";
            }
            else
            {
                btnlCapNhat.Text = "Cập Nhật";
                this.FrmQLSV_Load(sender, e);
            }
        }
        //*************XOA************************************
        private void btnlXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn xóa ?", "Xác nhận xóa ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                LopDTO l = new LopDTO();
                l.MaLop = Int32.Parse(txtlMaLop.Text);
                l.TenLop = txtlTenLop.Text;

                LopDAO.xoaLop(l);               
                this.FrmQLSV_Load(sender, e);
            }
        }


        //------------------------QUAN LY DANH MUC KHOA---------------------------
        //*************THEM************************************
        private void btnkThem_Click(object sender, EventArgs e)
        {
            if (btnkThem.Text.Equals("Thêm"))
            {
                this.xuLyTabKhoa(true, false, false, true, false, true);
                txtkMaKhoa.Text = "";
                txtkTenKhoa.Text = "";
                btnkThem.Text = "Hủy bỏ";
            }
            else
            {
                btnkThem.Text = "Thêm";
                this.xuLyTabKhoa(true, true, true, false, false, false);
                this.FrmQLSV_Load(sender, e);
            } 
        }
        //*************LUU************************************
        private void btnkLuu_Click(object sender, EventArgs e)
        {
            if (btnkThem.Text.Equals("Hủy bỏ"))
            {
                if (txtkTenKhoa.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {                                       
                    KhoaDTO k = new KhoaDTO();
                    k.TenKhoa = txtkTenKhoa.Text;

                    KhoaDAO.themKhoa(k);
                   
                    btnkThem.Text = "Thêm";
                    this.FrmQLSV_Load(sender, e);
                }
            }
            else
            {
                if (txtkTenKhoa.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {               
                                 
                    KhoaDTO k = new KhoaDTO();
                    k.MaKhoa = Int32.Parse(txtkMaKhoa.Text);
                    k.TenKhoa = txtkTenKhoa.Text;
                  
                    KhoaDAO.capNhatKhoa(k);

                    // huy bo
                    btnkCapNhat.Text = "Cập Nhật";

                    this.FrmQLSV_Load(sender, e);
                }
            }
        }
        //*************CAP NHAT************************************
        private void btnkCapNhat_Click(object sender, EventArgs e)
        {
            if (btnkCapNhat.Text.Equals("Cập Nhật"))
            {
                this.xuLyTabKhoa(false, true, false, true, false, true);
                btnlCapNhat.Text = "Hủy bỏ";
            }
            else
            {
                btnkCapNhat.Text = "Cập Nhật";
                this.FrmQLSV_Load(sender, e);
            }
        }
        //*************XOA************************************
        private void btnkXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn xóa ?", "Xác nhận xóa ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                KhoaDTO k = new KhoaDTO();
                k.MaKhoa = Int32.Parse(txtkMaKhoa.Text);
                k.TenKhoa = txtkTenKhoa.Text;

                KhoaDAO.xoaKhoa(k);                
                this.FrmQLSV_Load(sender, e);
            }
        }
        //------------------------QUAN LY DANH MUC DAN TOC---------------------------
        //*************THEM************************************
        private void btndtThem_Click(object sender, EventArgs e)
        {
            if (btndtThem.Text.Equals("Thêm"))
            {
                this.xuLyTabDanToc(true, false, false, true, false, true);
                txtdtMaDanToc.Text = "";
                txtdtTenDanToc.Text = "";
                btndtThem.Text = "Hủy bỏ";
            }
            else
            {
                btndtThem.Text = "Thêm";
                this.xuLyTabDanToc(true, true, true, false, false, false);
                this.FrmQLSV_Load(sender, e);
            } 
        }
        //*************LUU************************************
        private void btndtLuu_Click(object sender, EventArgs e)
        {
            if (btndtThem.Text.Equals("Hủy bỏ"))
            {
                if (txtdtTenDanToc.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {                    
                    DanTocDTO dt = new DanTocDTO();
                    dt.TenDanToc = txtdtTenDanToc.Text;

                    DanTocDAO.themDanToc(dt);
                    btndtThem.Text = "Thêm";

                    this.FrmQLSV_Load(sender, e);
                }
            }
            else
            {
                if (txtdtTenDanToc.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {

                    DanTocDTO dt = new DanTocDTO();
                    dt.MaDanToc = Int32.Parse(txtdtMaDanToc.Text);
                    dt.TenDanToc = txtdtTenDanToc.Text;

                    DanTocDAO.capNhatDanToc(dt);
                                       
                    btndtCapNhat.Text = "Cập Nhật";

                    this.FrmQLSV_Load(sender, e);
                }
            }
        }

        private void btndtCapNhat_Click(object sender, EventArgs e)
        {
            if (btndtCapNhat.Text.Equals("Cập Nhật"))
            {
                this.xuLyTabDanToc(false, true, false, true, false, true);
                btndtCapNhat.Text = "Hủy bỏ";
            }
            else
            {
                btndtCapNhat.Text = "Cập Nhật";
                this.FrmQLSV_Load(sender, e);
            }
        }

        private void btndtXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn xóa ?", "Xác nhận xóa ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                DanTocDTO dt = new DanTocDTO();
                dt.MaDanToc = Int32.Parse(txtdtMaDanToc.Text);
                dt.TenDanToc = txtdtTenDanToc.Text;

                DanTocDAO.xoaDanToc(dt);
                this.FrmQLSV_Load(sender, e);
            }
        }
        //------------------------QUAN LY DANH MUC TON GIAO---------------------------
        //*************THEM************************************
        private void btntgThem_Click(object sender, EventArgs e)
        {
            if (btntgThem.Text.Equals("Thêm"))
            {
                this.xuLyTabTonGiao(true, false, false, true, false, true);
                txttgMaTonGiao.Text = "";
                txttgTenTonGiao.Text = "";
                btntgThem.Text = "Hủy bỏ";
            }
            else
            {
                btntgThem.Text = "Thêm";
                this.xuLyTabTonGiao(true, true, true, false, false, false);
                this.FrmQLSV_Load(sender, e);
            } 
        }

        private void btntgLuu_Click(object sender, EventArgs e)
        {
            if (btntgThem.Text.Equals("Hủy bỏ"))
            {
                if (txttgTenTonGiao.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {                    
                    TonGiaoDTO tg = new TonGiaoDTO();
                    tg.TenTonGiao = txttgTenTonGiao.Text;

                    TonGiaoDAO.themTonGiao(tg);                   
                    btntgThem.Text = "Thêm";

                    this.FrmQLSV_Load(sender, e);
                }
            }
            else
            {
                if (txttgTenTonGiao.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    TonGiaoDTO tg = new TonGiaoDTO();
                    tg.MaTonGiao = Int32.Parse(txttgMaTonGiao.Text);
                    tg.TenTonGiao = txttgTenTonGiao.Text;

                    TonGiaoDAO.capNhatTonGiao(tg);
                    
                    btntgCapNhat.Text = "Cập Nhật";

                    this.FrmQLSV_Load(sender, e);
                }
            }
        }

        private void btntgCapNhat_Click(object sender, EventArgs e)
        {
            if (btntgCapNhat.Text.Equals("Cập Nhật"))
            {
                this.xuLyTabTonGiao(false, true, false, true, false, true);
                btntgCapNhat.Text = "Hủy bỏ";
            }
            else
            {
                btntgCapNhat.Text = "Cập Nhật";
                this.FrmQLSV_Load(sender, e);
            }
        }

        private void btntgXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn xóa ?", "Xác nhận xóa ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                TonGiaoDTO tg = new TonGiaoDTO();
                tg.MaTonGiao = Int32.Parse(txttgMaTonGiao.Text);
                tg.TenTonGiao = txttgTenTonGiao.Text;

                TonGiaoDAO.xoaTonGiao(tg);                
                this.FrmQLSV_Load(sender, e);
            }
        }
        //------------------------QUAN LY DANH MUC QUAN HE---------------------------
        //*************THEM************************************
        private void btnqhThem_Click(object sender, EventArgs e)
        {
            if (btnqhThem.Text.Equals("Thêm"))
            {
                this.xuLyTabQuanHe(true, false, false, true, false, true);
                txtqhMaQuanHe.Text = "";
                txtqhTenQuanHe.Text = "";
                btnqhThem.Text = "Hủy bỏ";
            }
            else
            {
                btnqhThem.Text = "Thêm";
                this.xuLyTabQuanHe(true, true, true, false, false, false);
                this.FrmQLSV_Load(sender, e);
            } 
        }

        private void btnqhLuu_Click(object sender, EventArgs e)
        {
            if (btnqhThem.Text.Equals("Hủy bỏ"))
            {
                if (txtqhTenQuanHe.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    QuanHeDTO qh = new QuanHeDTO();
                    qh.TenQuanHe = txtqhTenQuanHe.Text;

                    QuanHeDAO.themQuanHe(qh);                   
                    btnqhThem.Text = "Thêm";

                    this.FrmQLSV_Load(sender, e);
                }
            }
            else
            {
                if (txtqhTenQuanHe.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {                 
                    QuanHeDTO qh = new QuanHeDTO();
                    qh.MaQuanHe = Int32.Parse(txtqhMaQuanHe.Text);
                    qh.TenQuanHe = txtqhTenQuanHe.Text;

                    QuanHeDAO.capNhatQuanHe(qh);             
                    btnqhCapNhat.Text = "Cập Nhật";

                    this.FrmQLSV_Load(sender, e);
                }
            }
        }

        private void btnqhCapNhat_Click(object sender, EventArgs e)
        {
            if (btnqhCapNhat.Text.Equals("Cập Nhật"))
            {
                this.xuLyTabQuanHe(false, true, false, true, false, true);
                btnqhCapNhat.Text = "Hủy bỏ";
            }
            else
            {
                btnqhCapNhat.Text = "Cập Nhật";
                this.FrmQLSV_Load(sender, e);
            }
        }

        private void btnqhXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn xóa ?", "Xác nhận xóa ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                QuanHeDTO qh = new QuanHeDTO();
                qh.MaQuanHe = Int32.Parse(txtqhMaQuanHe.Text);
                qh.TenQuanHe = txtqhTenQuanHe.Text;

                QuanHeDAO.xoaQuanHe(qh);               
                this.FrmQLSV_Load(sender, e);
            }
        }

        private void tabPage5_Click(object sender, EventArgs e)
        {

        }
        //------------------------QUAN LY DANH MUC NAM HOC---------------------------------
        private void btnnhThem_Click(object sender, EventArgs e)
        {
            if (btnnhThem.Text.Equals("Thêm"))
            {
                this.xuLyTabNamHoc(true, false, false, true, false, true);
                txtqhMaQuanHe.Text = "";
                txtnhMaNamHoc.Text = "";
                txtnhTenNamHoc.Text = "";
                
                btnnhThem.Text = "Hủy bỏ";
            }
            else
            {
                btnnhThem.Text = "Thêm";
                this.xuLyTabNamHoc(true, true, true, false, false, false);
                this.FrmQLSV_Load(sender, e);
            } 
        }

        private void btnnhLuu_Click(object sender, EventArgs e)
        {
            if (btnnhThem.Text.Equals("Hủy bỏ"))
            {
                if (txtnhTenNamHoc.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    NamHocDTO nh = new NamHocDTO();
                    nh.TenNamHoc = txtnhTenNamHoc.Text;
                    NamHocDAO.themNamHoc(nh);

                   

                    this.FrmQLSV_Load(sender, e);
                }
            }
            else
            {
                if (txtnhTenNamHoc.Text.Equals(""))
                {
                    MessageBox.Show("Vui lòng nhập dữ liệu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    NamHocDTO nh = new NamHocDTO();
                    nh.TenNamHoc = txtnhTenNamHoc.Text;
                    nh.MaNamHoc = Int32.Parse (txtnhMaNamHoc.Text);

                    NamHocDAO.capNhatNamHoc(nh);


                    this.FrmQLSV_Load(sender, e);
                }
            }
        }

        private void btnnhCapNhat_Click(object sender, EventArgs e)
        {
            if (btnnhCapNhat.Text.Equals("Cập Nhật"))
            {
                this.xuLyTabNamHoc(false, true, false, true, false, true);
                btnnhCapNhat.Text = "Hủy bỏ";
            }
            else
            {
                btnnhCapNhat.Text = "Cập Nhật";
                this.FrmQLSV_Load(sender, e);
            }
        }

        private void btnnhXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc muốn xóa ?", "Xác nhận xóa ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                NamHocDTO nh = new NamHocDTO();
                nh.TenNamHoc = txtnhTenNamHoc.Text;
                nh.MaNamHoc = Int32.Parse(txtnhMaNamHoc.Text);

                NamHocDAO.xoaNamHoc(nh);

              
                this.FrmQLSV_Load(sender, e);
            }
        }

        private void lbTSDML_Click(object sender, EventArgs e)
        {

        }
        //-------------------------------------Het-------------------------------------------------------------
    }
}
